use hypers::prelude::*;
use hypers::tracing::info;

// http://127.0.0.1:7878/download
async fn download(_req: Request) -> impl Responder {
    let mut res = Response::default();
    res.download("download/Cargo.toml");
    res
}

// http://127.0.0.1:7878/send_file
async fn send_file(req: Request) -> Response {
    let mut res = Response::default();
    res.file("download/src/main.rs", req.headers()).await;
    res
}

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt().init();
    let mut root = Router::default();
    root.get("/download", download);
    root.get("/send_file",send_file);
    info!("root = {:#?}", root);
    let listener = hypers::TcpListener::bind("127.0.0.1:7878").await?;
    hypers::listen(root, listener).await
}
/*
filename
                .replace('\\', "\\\\")
                .replace('\"', "\\\"")
                .replace('\r', "\\\r")
                .replace('\n', "\\\n") */
